package com.rxjava;

import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by kkmike999 on 16/3/21.
 */
public class OperatorsTest {

    public static void main(String[] args) {
        Character[] array = {'a', 'b', 'c'};

//        flatMap(array);

        skip(array);
    }

    private static void flatMap(Character[] array) {
        Observable.from(array)
                .flatMap(new Func1<Character, Observable<Integer>>() {
                    int i = 0;

                    public Observable<Integer> call(Character character) {
                        System.out.println("i=" + i++);

                        return Observable.just((int) character);
                    }
                })
                .subscribe(new Action1<Integer>() {
                    public void call(Integer integer) {
                        System.out.println(integer + "\n");
                    }
                });
    }

    private static void skip(Character[] array) {
        Observable.from(array)
                .skipLast(1)
                .subscribe(new Action1<Character>() {
                    public void call(Character character) {
                        System.out.println(character);
                    }
                });
    }
}
